import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:squat_easy/generated/assets.dart';
import 'package:squat_easy/se_main/se_mine/se_mine_base_page.dart';
import 'package:squat_easy/se_main/se_mine/se_setting/se_setting_logic.dart';
import 'package:squat_easy/se_service/se_user_service.dart';
import 'package:ylm_ui_kit/ylm_ui_kit.dart';

class SeSettingPage extends StatelessWidget {
  SeSettingPage({super.key});

  final SeSettingLogic logic = SeSettingLogic()..init();

  @override
  Widget build(BuildContext context) {
    return SeMineBasePage(
      title: const ImageWidget.asset(Assets.pngTitleSetting, width: 84),
      child: ValueListenableBuilder(
        valueListenable: SeUserService.instance.notifierOfMineInfo,
        builder: (BuildContext context, value, Widget? child) {
          return Column(
            children: [
              _buildIcon().center().paddingTop(40.w),
              _buildTitle().paddingTop(15.w),
              _buildItem(
                'Id：${value.userId ?? ''}',
                right: ButtonWidget.icon(
                  ImageWidget.asset(Assets.pngCopy, width: 22.w),
                  onTap: () => CommonOperate.copy(
                    value.userId ?? '',
                    toast: 'Copy Success',
                  ),
                ),
              ).padding(top: 8.w),
              // _buildItem(
              //   'Auto Translate',
              //   onTap: () {},
              //   right: ValueListenableBuilder(
              //     valueListenable: logic.autoTranslate,
              //     builder: (BuildContext context, bool value, Widget? child) {
              //       return ButtonWidget.icon(
              //         ImageWidget.asset(value ? Assets.pngMineSwitchOn : Assets.pngMineSwitchOff),
              //         width: 43.w,
              //         height: 19.w,
              //         onTap: logic.onTaoAutoTranslate,
              //       );
              //     },
              //   ),
              // ).padding(top: 16.w),
              _buildItem(
                'Log Out Of Account',
                onTap: logic.logout,
              ).padding(top: 16.w),
              _buildItem(
                'Delete Account',
                onTap: logic.deleteAccount,
              ).padding(top: 16.w),
            ],
          ).paddingHorizontal(16.w);
        },
      ),
    );
  }

  Widget _buildIcon() => IconWidget.image(Assets.pngLogo, size: 100.w);

  Widget _buildTitle() => CommonTextUtils.getText('SquatEasy', fontSize: 20);

  Widget _buildItem(String title, {VoidCallback? onTap, Widget? right}) {
    return ButtonWidget(
      onTap: onTap,
      height: 54.w,
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      backgroundColor: Colors.black,
      borderRadius: 12.w,
      child: Row(
        children: [
          TextWidget.oneLine(text: title, fontSize: 19, color: Colors.white).expanded(),
          if (right != null) right,
        ],
      ),
    ).paddingHorizontal(20.w);
  }
}
